package com.leador.assist;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.leador.service.LBSTraceService;

import java.lang.ref.WeakReference;

/**
 * Created by liuha on 2016/9/11.
 */
public class LBSServiceHandler extends Handler {
    private WeakReference weakReference = null;

    public LBSServiceHandler(LBSTraceService lbsTraceService) {
        this.weakReference = new WeakReference(lbsTraceService);
    }

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        LBSTraceService lbsTraceService = (LBSTraceService) this.weakReference.get();
        if(lbsTraceService != null){
            switch (msg.what){
                case 1: //socket 服务启动成功
                    lbsTraceService.socketConnectSucess();
                    return;
                case 19: //socket连接失败 停止服务
                    lbsTraceService.netUnAvailable();
                    return;
                case 4://重启socket SocketMananger
                    lbsTraceService.reStartScocket();
                    return;
                case 11:
                     //将 LBSClientHandler -> LBSServiceHandler
                     lbsTraceService.setMessage(msg);
                    return;
                case 14:
                     //设置时间周期
                     lbsTraceService.setIntervalMessage(msg);
                    return;
                case 16: //停止服务
                    lbsTraceService.stopTrack();
                    return;
                case 24://网络连接后重启Socket服务
                    lbsTraceService.reStartSocketByNetConnect();
                    return;
                case 25://网络连接后重启HTTP服务
                    lbsTraceService.reStartHttpByNetConnect(true);
                    return;
                case 30://断开socket连接
                    lbsTraceService.socketDisconnet();
                    return;
                case 31://http断网了缓存
                    lbsTraceService.setHttpCacheNotity();
                    return;
                case 32://http断网了缓存
                    lbsTraceService.setHttpCacheAi();
                    return;
                case 173: //http停止
                    lbsTraceService.httpSotp();
                    return;
                case 141://服务停止
                    lbsTraceService.stopService();
                    return;
                case 142://无网络情况下缓存开启
                    lbsTraceService.reStartHttpByNetConnect(false);
                    return;
            }
        }
    }
}
